Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mismatch of Range#cover? and Range#include? out of shared folder #1053

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Aug 14, 2023

This is based on an observation made by @richardboehme in the Natalie project, split over these two commits:

natalie-lang/natalie@a263a4d#diff-269d1f98177fca45189f918bb4282631ff1dcaaac8f1d793c3fea82b3034b73f
natalie-lang/natalie@00ccd22

It turns out cover? and include? do not behave the same for this query, so I moved this one out of the shared folder and into the two separate specs.
I had to guess what the spec was actually testing, so the descriptions for the test are probably up for improvement.

@@ -57,7 +57,6 @@
it "returns true if argument is less than the last value of the range and greater than the first value" do
(20..30).send(@method, 28).should be_true
('e'..'h').send(@method, 'g').should be_true
("\u{999}".."\u{9999}").send @method, "\u{9995}"
Copy link
Member

@andrykonchin andrykonchin Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

There is a missing should so no check actually performed.

But titles of the proposed new cases for include?/cover? don't describe their behaviour precisely.

The #cover? method returns true because it compares begin/end and value with <=> (or <, >) methods and indeed "\u{999}" < "\u{9995}" < "\u{9999}".

But #include? for non-ascii String begin/end uses the #succ method (that seems alphabetic-aware) and iterates from begin to end with #succ looking for a value. But "\u{9999}" and even "\u{9995}" isn't reachable from "\u{999}" - the largest reachable symbol is "\u{9b6}" (I suppose because "\u{999}" and "\u{9995}" belong to different alphabets). I assume #succ and consequently #include? should work well with characters of the same alphabet only.

So I would suggest changing titles of the new cases to describe the methods behaviour better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the descriptions. The inner encoding noob inside of me thinks they are correct now, so check them again please ;)

@andrykonchin andrykonchin merged commit 30be6b9 into ruby:master Aug 17, 2023
10 checks passed
@andrykonchin
Copy link
Member

Thank you for the fix!

@herwinw herwinw deleted the range_include_cover branch August 17, 2023 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants